﻿using System;
using Autofac;
using Autofac.Configuration.Core;
using Autofac.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;

namespace GenericHostSample
{
    internal class AutofacContainerFactory : IServiceProviderFactory<IContainer>
    {
        public IContainer CreateBuilder(IServiceCollection services)
        {
            // Create the container builder.
            var builder = new ContainerBuilder();
            builder.Populate(services);
            builder.Register(c => new MyModule() {Name = "姚世荣", Age = 30});

            return builder.Build();
        }

        public IServiceProvider CreateServiceProvider(IContainer container)
        {
            var com = container.Resolve<MyModule>();
            return new AutofacServiceProvider(container);
        }
    }
}